package com.wzl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzl.dao.SysHistoryTrendMapper;
import com.wzl.entity.SysHistoryTrend;
import com.wzl.service.SysHistoryTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * (SysHistoryTrend)表服务实现类
 *
 * @author wzl
 * @since 2022-05-02 20:51:37
 */
@Service("sysHistoryTrendService")
public class SysHistoryTrendServiceImpl extends ServiceImpl<SysHistoryTrendMapper, SysHistoryTrend> implements SysHistoryTrendService {

    @Autowired
    SysHistoryTrendMapper sysHistoryTrendMapper;

    @Override
    public Map<String, List<String>> getAll() {

        List<SysHistoryTrend> sysHistoryTrends = sysHistoryTrendMapper.selectList(new QueryWrapper<SysHistoryTrend>().orderByAsc("id").last("limit 56"));

        Map<String, List<String>> historyTrendMap = new HashMap<>();
        //时间
        List<String> dateList = sysHistoryTrends.stream().map(SysHistoryTrend::getDate).collect(Collectors.toList());
        //累计确诊
        List<String> connumList = sysHistoryTrends.stream().map(SysHistoryTrend::getConnum).collect(Collectors.toList());
        //累计治愈
        List<String> curenumList = sysHistoryTrends.stream().map(SysHistoryTrend::getCurenum).collect(Collectors.toList());
        //累计死亡
        List<String> deathnumList = sysHistoryTrends.stream().map(SysHistoryTrend::getDeathnum).collect(Collectors.toList());

        historyTrendMap.put("dateList", dateList);
        historyTrendMap.put("connumList", connumList);
        historyTrendMap.put("curenumList", curenumList);
        historyTrendMap.put("deathnumList", deathnumList);

        return historyTrendMap;
    }
}

